#include<iostream>
using namespace std;
struct TreeNode {
     int val;
     TreeNode *left;
     TreeNode *right;
 };

class Solution {
public:
    int minDepth(TreeNode* root) {
        if(root==NULL)return 0;
        int left=minDepth(root->left);
        int right=minDepth(root->right);
        if(left==0)return right+1;
        if(right==0)return left+1;
        return left>right?right+1:left+1;
    }
};